package org.to_zero.ssm.sdm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.to_zero.ssm.sdm.entity.Team;
import org.to_zero.ssm.sdm.entity.vo.ResponseEntity;
import org.to_zero.ssm.sdm.service.TeamService;

@RestController
@RequestMapping("/admin/team")
public class TeamController {

    @Autowired
    private TeamService teamService;

    @GetMapping("selectMap")
    public ResponseEntity selectMap() {
        return teamService.handleTeamList();
    }

    @GetMapping("query")
    public ResponseEntity query(Team team) {
        return teamService.findTeamByCondition(team);
    }

    @PostMapping("update")
    public ResponseEntity update(@RequestBody Team team) {
        return teamService.update(team);
    }

    @DeleteMapping("delete/{id}")
    public ResponseEntity delete(@PathVariable Integer id) {
        return teamService.deleteById(id);
    }

    @DeleteMapping("batchDelete/{ids}")
    public ResponseEntity batchDelete(@PathVariable Integer[] ids) {
        return teamService.deleteByIds(ids);
    }

    @GetMapping("teamLeaderMap/{id}")
    public ResponseEntity teamLeaderMap(@PathVariable Integer id) {
        return teamService.teamLeaderMap(id);
    }

    @GetMapping("checkMember/{id}")
    public ResponseEntity checkMember(@PathVariable Integer id) {
        return teamService.checkMember(id);
    }

    @GetMapping("unAllocated/{id}")
    public ResponseEntity unAllocated(@PathVariable Integer id) {
        return teamService.unAllocatedAndMemberList(id);
    }

    @GetMapping("allotMember")
    public ResponseEntity allotMember(@RequestParam("ids") Integer[] ids, Team team) {
        return teamService.allotMember(ids, team);
    }

}
